package Stack;

/**
 * 括号的匹配
 */
public class Brace {

    public static void main(String[] args) {
        System.out.println(solution("({})"));
    }

    private static boolean solution(String braceStr){
        Stack<Character> cstack = new ArrayStack<Character>();
        char[] chars = braceStr.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i] == '(' || chars[i] == '[' || chars[i] == '{'){
                cstack.push(chars[i]);
            } else {
                Character peek = cstack.peek();
                if(chars[i] == ')' &&  peek.equals('(')){
                    cstack.pop();
                    continue ;
                }
                if(chars[i] == ']' && peek.equals('[')){
                    cstack.pop();
                    continue ;
                }
                if(chars[i] == '}' && peek.equals('{')){
                    cstack.pop();
                    continue ;
                }
            }


        }
        if(cstack.isEmpty()){
            return true;
        }
        return false;
    }
}
